package biz.obake.team.touchprotector.nolockapps;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import biz.obake.team.touchprotector.R;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class NoLockAppsActivity extends androidx.appcompat.app.c {
    private ListView t;
    private b u;

    private class b extends BaseAdapter {

        /* renamed from: b  reason: collision with root package name */
        ArrayList<c> f1762b;

        /* renamed from: c  reason: collision with root package name */
        ExecutorService f1763c;

        /* renamed from: d  reason: collision with root package name */
        Future f1764d;
        Handler e;

        class a implements Runnable {

            /* renamed from: biz.obake.team.touchprotector.nolockapps.NoLockAppsActivity$b$a$a  reason: collision with other inner class name */
            class C0082a implements Runnable {

                /* renamed from: b  reason: collision with root package name */
                final /* synthetic */ ArrayList f1766b;

                C0082a(ArrayList arrayList) {
                    this.f1766b = arrayList;
                }

                public void run() {
                    b.this.f1762b.clear();
                    b.this.f1762b.addAll(this.f1766b);
                    b.this.notifyDataSetChanged();
                }
            }

            a(NoLockAppsActivity noLockAppsActivity) {
            }

            private void a(ArrayList<c> arrayList) {
                Collections.sort(arrayList);
                b.this.e.post(new C0082a(arrayList));
            }

            public void run() {
                PackageManager packageManager = biz.obake.team.android.a.a().getPackageManager();
                List<PackageInfo> installedPackages = packageManager.getInstalledPackages(1);
                ArrayList arrayList = new ArrayList();
                long currentTimeMillis = System.currentTimeMillis();
                for (PackageInfo next : installedPackages) {
                    if (!Thread.interrupted()) {
                        if (!"biz.obake.team.touchprotector".equals(next.packageName) && !"com.android.systemui".equals(next.packageName)) {
                            if (packageManager.getLaunchIntentForPackage(next.packageName) != null) {
                                c cVar = new c(NoLockAppsActivity.this, packageManager, next);
                                if (cVar.b()) {
                                    arrayList.add(cVar);
                                }
                            }
                            long currentTimeMillis2 = System.currentTimeMillis();
                            if (currentTimeMillis2 - currentTimeMillis > 200) {
                                a(arrayList);
                                currentTimeMillis = currentTimeMillis2;
                            }
                        }
                    } else {
                        return;
                    }
                }
                a(arrayList);
            }
        }

        /* renamed from: biz.obake.team.touchprotector.nolockapps.NoLockAppsActivity$b$b  reason: collision with other inner class name */
        class C0083b implements View.OnClickListener {

            /* renamed from: b  reason: collision with root package name */
            final /* synthetic */ c f1768b;

            /* renamed from: c  reason: collision with root package name */
            final /* synthetic */ CompoundButton f1769c;

            C0083b(b bVar, c cVar, CompoundButton compoundButton) {
                this.f1768b = cVar;
                this.f1769c = compoundButton;
            }

            public void onClick(View view) {
                boolean z = !this.f1768b.e();
                this.f1768b.d(z);
                this.f1769c.setChecked(z);
            }
        }

        private b() {
            this.f1762b = new ArrayList<>();
            this.f1763c = Executors.newFixedThreadPool(1);
            this.e = new Handler();
            this.f1764d = this.f1763c.submit(new a(NoLockAppsActivity.this));
        }

        /* access modifiers changed from: private */
        public void b() {
            this.f1764d.cancel(true);
            this.e.removeCallbacksAndMessages((Object) null);
        }

        public int getCount() {
            return this.f1762b.size();
        }

        public Object getItem(int i) {
            return this.f1762b.get(i);
        }

        public long getItemId(int i) {
            return 0;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewGroup viewGroup2 = (ViewGroup) view;
            if (viewGroup2 == null) {
                viewGroup2 = (ViewGroup) NoLockAppsActivity.this.getLayoutInflater().inflate(R.layout.nolockapps_listview, viewGroup, false);
            }
            c cVar = this.f1762b.get(i);
            if (cVar != null) {
                viewGroup2.setTag(cVar);
                CompoundButton compoundButton = (CompoundButton) viewGroup2.findViewById(R.id.checkBox);
                ((ImageView) viewGroup2.findViewById(R.id.iconView)).setImageDrawable(cVar.c());
                ((TextView) viewGroup2.findViewById(R.id.textView)).setText(cVar.f1771c);
                compoundButton.setChecked(cVar.e());
                compoundButton.setOnClickListener(new C0083b(this, cVar, compoundButton));
            }
            return viewGroup2;
        }
    }

    private class c implements Comparable<c> {

        /* renamed from: b  reason: collision with root package name */
        String f1770b = null;

        /* renamed from: c  reason: collision with root package name */
        String f1771c = null;

        c(NoLockAppsActivity noLockAppsActivity, PackageManager packageManager, PackageInfo packageInfo) {
            ApplicationInfo applicationInfo;
            if (packageInfo != null && (applicationInfo = packageInfo.applicationInfo) != null) {
                this.f1770b = packageInfo.packageName;
                this.f1771c = applicationInfo.loadLabel(packageManager).toString();
            }
        }

        /* renamed from: a */
        public int compareTo(c cVar) {
            boolean e = e();
            return e != cVar.e() ? e ? -1 : 1 : this.f1771c.compareTo(cVar.f1771c);
        }

        /* access modifiers changed from: package-private */
        public boolean b() {
            return (this.f1770b == null || this.f1771c == null) ? false : true;
        }

        /* access modifiers changed from: package-private */
        public Drawable c() {
            try {
                return biz.obake.team.android.a.a().getPackageManager().getApplicationIcon(this.f1770b);
            } catch (PackageManager.NameNotFoundException unused) {
                return null;
            }
        }

        /* access modifiers changed from: package-private */
        public void d(boolean z) {
            b b2 = b.b();
            a a2 = b2.a(this.f1770b);
            if (a2 == null) {
                a2 = new a();
            }
            a2.f1772a = z;
            b2.d(this.f1770b, a2);
        }

        /* access modifiers changed from: package-private */
        public boolean e() {
            a a2 = b.b().a(this.f1770b);
            return a2 != null && a2.f1772a;
        }
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.nolockapps_activity);
        this.t = (ListView) findViewById(R.id.listView);
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        this.u.b();
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        b bVar = new b();
        this.u = bVar;
        this.t.setAdapter(bVar);
    }
}
